package com.mit.web.util
{
	import com.mit.web.config.Constants;
	
	import flash.display.DisplayObject;
	import flash.utils.ByteArray;
	
	import mx.core.Application;
	import mx.core.FlexGlobals;
	import mx.managers.BrowserManager;
	import mx.managers.IBrowserManager;
	import mx.rpc.AsyncToken;
	import mx.utils.URLUtil;

	public class FlexUtil
	{
		private static var _rootUrl:String;
		public function FlexUtil()
		{
		}

		public static function getCenterX():Number{
			return FlexGlobals.topLevelApplication.stage.stageWidth/2;
			
		}
		
		public static function getCenterY():Number{
			return FlexGlobals.topLevelApplication.stage.stageHeight/2;
		}
		
		public static function getRootURL():String{
			if(!_rootUrl){
				var browserManager:IBrowserManager = BrowserManager.getInstance();
				browserManager.init();
				var url:String = browserManager.url;
				var fullUrl:String = URLUtil.getFullURL(url, url);
				var _idx:int = fullUrl.indexOf(Constants.PROJECT_ROOT);
				_rootUrl =  fullUrl.substring(0,_idx + Constants.PROJECT_ROOT.length) + "/";
			}
			return _rootUrl;
		}
		
		public static function deepClone(src:Object):Object{
			var myBA:ByteArray = new ByteArray();
			myBA.writeObject(src);
			myBA.position = 0;
			return(myBA.readObject());
		}
	}
}